
//层级
TIER = {
    TIER1 : 1,
    TIER2 : 2,
    TIER3 : 3,
    TIER4 : 4,
    TIER5 : 5,
    TIER6 : 6,
    TIER7 : 7,      //弹框层
}
//弹框提示类
cc.Class({
    extends: cc.BaseClass,

    properties: {
        count : 1,
        tipNodePre: cc.Prefab,              //提示框
        tipPanelPre: cc.Prefab,             //提示面板
    },

    onLoad () {
        this.initNodePool();
        this.node.zIndex = TIER.TIER7;
    },

    start () {
        this.registerEvent();
    },

    registerEvent:function(){
        ClientNotify.register(CLIENT_NOTIFY_TYPE.TIP,this.onTip,this);
        ClientNotify.register(CLIENT_NOTIFY_TYPE.TIPPANEL,this.onTipPanel,this);
    },

    initNodePool:function(){
        this.tipPool = new cc.NodePool();
        for(let i = 0; i < this.count; i++){
            let tipNode = cc.instantiate(this.tipNodePre);
            this.tipPool.put(tipNode);
        }

        this.tipPanelPool = new cc.NodePool();
        let tipPanelNode = cc.instantiate(this.tipPanelPre);
        this.tipPanelPool.put(tipPanelNode);
    },

    createTipNode:function(parentNode,des){
        let tipNode = null;
        if(this.tipPool.size() > 0){
            tipNode = this.tipPool.get();
        }else{
            tipNode = cc.instantiate(this.tipNodePre);
        }
        tipNode.parent = parentNode;
        tipNode.children[1].getComponent(cc.Label).string = des;

        var act = cc.sequence(cc.delayTime(0.8), cc.spawn(cc.moveTo(0.5, cc.Vec2(0, 300)), cc.fadeOut(0.5)));
        tipNode.runAction(act);
    },

    createTipPanel:function(parentNode,data){
        let tipPanelNode = null;
        if(this.tipPanelPool.size() > 0){
            tipPanelNode = this.tipPanelPool.get();
        }else{
            tipPanelNode = cc.instantiate(this.tipPanelPre);
        }
        tipPanelNode.parent = parentNode;
        tipPanelNode.getComponent("tipPanelPre").initData(data);
    },

    //显示弹框
    onTip:function(data,target){
        var self = target;
        var parent = self.node;
        self.createTipNode(parent,data);
    },

    //显示提示面板
    onTipPanel:function(data,target){
        var self = target;
        var parent = self.node;
        self.createTipPanel(parent,data);
    },

    onDestroy: function() {
        ClientNotify.removeByType(CLIENT_NOTIFY_TYPE.TIP);
        ClientNotify.removeByType(CLIENT_NOTIFY_TYPE.TIPPANEL);
    },
});
